<template>
  <div>
    <ul class="radio-group"
        :key="1">
      <li class="radio">
        <label for="one"
               @click="change1('1')">
          <img src="../assets/icon/check.png"
               v-show="check1 === '2'">
          <img src="../assets/icon/checked.png"
               v-show="check1 === '1'">
          <input type="radio"
                 id="one"
                 value="1"
                 v-model="check1">为自己预约</label>
      </li>
      <li class="radio"
          @click="change1('2')">
        <label for="two">
          <img src="../assets/icon/check.png"
               v-show="check1 === '1'">
          <img src="../assets/icon/checked.png"
               v-show="check1 === '2'">
          <input type="radio"
                 id="two"
                 value="2"
                 v-model="check1">为他人预约</label>
      </li>
    </ul>
    <slot name="other"></slot>
    <ul class="radio-group"
        :key="2">
      <li class="radio">
        <label for="day"
               @click="change2('1')">
          <img src="../assets/icon/check.png"
               v-show="check2 === '2'">
          <img src="../assets/icon/checked.png"
               v-show="check2 === '1'">
          <input type="radio"
                 id="day"
                 value="1"
                 v-model="check2">预约一天</label>
      </li>
      <li class="radio"
          @click="change2('2')">
        <label for="days">
          <img src="../assets/icon/check.png"
               v-show="check2 === '1'">
          <img src="../assets/icon/checked.png"
               v-show="check2 === '2'">
          <input type="radio"
                 id="days"
                 value="2"
                 v-model="check2">预约多天</label>
      </li>
    </ul>
  </div>
</template>
<script>
export default {
  name: 'AppointmentRadio',
  data() {
    return {
      check1: '',
      check2: ''
    }
  },
  props: {
    appointmentPeople: String,
    timePeriod: String
  },
  methods: {
    changeProp() {
      this.$emit('change', { appointmentPeople: this.check1, timePeriod: this.check2 })
      this.$emit('change2', { appointmentPeople: this.check1, timePeriod: this.check2 })
    },
    change1(val) {
      console.log('change1')
      this.check1 = val
      this.changeProp()
    },
    change2(val) {
      console.log('change2')
      this.check2 = val
      this.changeProp()
    }
  },
  activated() {
    this.check1 = this.appointmentPeople
    this.check2 = this.timePeriod
  }
}
</script>
<style lang="stylus" scoped>
@import '~styles/varibles.styl';
.radio-group
  background: $white;
  overflow: hidden;
  padding: 0.26rem 0;
  margin-bottom: 1px;
  input
    position: absolute;
    left: -9999em;
  img
    width: 0.48rem;
    height: 0.48rem;
    position: relative;
    top: -0.03rem;
  .radio
    width: 50%;
    padding: 0 0.76rem;
    float: left;
    line-height: 0.48rem;
    color: $darkText;
    font-size: 0.3rem;
    &:first-child
      border-right: 1px solid #F4F4F4;
    label
      display: block;
      font-weight: 500;
</style>
